package com.sbc.liteflow.controller;

import com.sbc.liteflow.dto.ChangeCardParam;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: 测试控制类
 * @Author: songbaicheng
 * @Create: 2024/11/13 20:31
 **/
@RestController
public class TestController {

    @Resource
    private FlowExecutor flowExecutor;

    /**
     * 测试流程
     */
    @GetMapping("/test")
    public ResponseEntity<String> test() {
        LiteflowResponse response = flowExecutor.execute2Resp("test-chain");

        // 获取每个节点的执行步骤
        System.out.println("节点执行步骤：" + response.getExecuteSteps());

        return ResponseEntity.ok("执行成功");
    }

    /**
     * 充值流程
     */
    @GetMapping("/recharge/{corpId}")
    public ResponseEntity<String> recharge(@PathVariable String corpId) {

        // 充值流程
        LiteflowResponse response = flowExecutor.execute2Resp("recharge-chain", corpId);

        return response.isSuccess() ? ResponseEntity.ok("执行成功！") : ResponseEntity.ok("执行失败");
    }

    /**
     * 变更银行卡流程
     */
    @GetMapping("/changeCard")
    public ResponseEntity<String> changeCard(@RequestBody ChangeCardParam param) {

        // 执行流程
        LiteflowResponse response = flowExecutor.execute2Resp("recharge-chain", param);

        return response.isSuccess() ? ResponseEntity.ok("执行成功！") : ResponseEntity.ok("执行失败");
    }
}
